package com.leyou.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.leyou.vo.SkuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.leyou.entity.SkuEntity;
import com.leyou.service.SkuService;

import com.leyou.api.R;



/**
 * sku表,该表表示具体的商品实体,如黑色的 64g的iphone 8
 *
 * @author Daifeng
 * @email 2661184062@qq.com
 * @date 2020-12-25 16:44:47
 */
@RestController
@RequestMapping("/sku")
public class SkuController {
    @Autowired
    private SkuService skuService;


    /**
     * 信息
     */
    @RequestMapping("/info/{sid}")
    public R getInfoBySpuId(@PathVariable("sid") Long sid){
        List<SkuVo> sku = skuService.getInfoWithStockBySpuId(sid);
        return R.ok().put("data", sku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuEntity sku){
		skuService.save(sku);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
  //  @RequiresPermissions("leyou:sku:update")
    public R update(@RequestBody SkuEntity sku){
		skuService.updateById(sku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		skuService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
